package com.wqt.practice;

import com.wqt.Student;
import java.util.*;
import java.util.function.Consumer;


public class HashSetDemo {
    public static void main(String[] args) {
        ArrayList<String> list = new ArrayList<>();
        list.add("zhangsan");
        list.add("lisi");
        list.add("zhangsan");
        System.out.println(list);

        ArrayList<String> newList=new ArrayList<>((new HashSet<String>(list)));
        System.out.println(newList);

        // 创建集合对象
        HashSet<String> hashSet  = new HashSet<>();
        hashSet.add("zhangqi");
        hashSet.add("youke");
        hashSet.add("zhaoxin");
        hashSet.add("zhangqi");
        hashSet.add("youke");
        System.out.println(hashSet);
        Iterator<String> iterator = hashSet.iterator();
        while (iterator.hasNext()) {
            String next = iterator.next();
            System.out.println(next);

        }

        for (String name : hashSet){
            System.out.println("name="+name);
        }
        int[] arr = {1,2,3,4,5,6,7,8,9,10};
        for (int i : arr) {
            System.out.println(i);
        }
        hashSet.forEach(new Consumer<String>() {
            @Override
            public void accept(String s) {
                System.out.println(s);
            }
        });
        hashSet.forEach(s-> System.out.println(s));

        hashSet.forEach(System.out::println);
        Student student  = new Student("zhangsan", 18);

        System.out.println(student.toString());
    }
}